/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        trace_win.h
// Purpose:     
// Author:      syy
// Modified by: 
// Created:     2014/1/3 15:42
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#ifndef PBQ_SYSTEM_WRAPPERS_INTERFACE_GUARD_H_
#define PBQ_SYSTEM_WRAPPERS_INTERFACE_GUARD_H_

#include <stdio.h>
#include "../core.h"

#ifdef _MSC_VER
#include <windows.h>

class S_CORE_EXPORT LockGuard
{
public:
	LockGuard(CRITICAL_SECTION* pSession) : m_pSession(pSession)
	{
		if (m_pSession == NULL)
			return;

		::EnterCriticalSection(m_pSession);
	}
	~LockGuard()
	{
		if (m_pSession == NULL)
			return;

		::LeaveCriticalSection(m_pSession);		
	}

private:
	CRITICAL_SECTION*	m_pSession;
};

#endif

template<class T = char>
class autoptr
{
public:
	autoptr(T *buf) : m_buf(buf){}
	~autoptr(){
		if (m_buf)
		{
			delete m_buf;
			m_buf = NULL;
		}
	}
private:
	T *m_buf;
};

template<class T = char>
class autoptr_arr
{
public:
	autoptr_arr(T *buf) : m_buf(buf){}
	~autoptr_arr(){
		delete []m_buf;
	}
private:
	T *m_buf;
};

#endif  // PBQ_SYSTEM_WRAPPERS_INTERFACE_GUARD_H_
